package com.csy.property.controller.community;

import cn.hutool.core.util.IdUtil;
import com.csy.commons.core.controller.BaseController;
import com.csy.commons.core.domain.BaseResponse;
import com.csy.commons.core.page.PageResult;
import com.csy.property.community.domain.AjUnit;
import com.csy.property.community.domain.vo.AjRoomVo;
import com.csy.property.community.domain.vo.RoomTree;
import com.csy.property.community.mapper.AjRoomMapper;
import com.csy.property.community.service.AjRoomService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: sunxx
 * @Date: 2024/4/23 - 04 - 23 - 10:06
 * @Description: com.sxx.ajcommunity.web.controller.community
 * @version: 1.0
 */
@RestController
@RequestMapping("/system/room")
public class AjRoomController extends BaseController {

    @Resource
    private AjRoomService ajRoomService;
    private final String CODE_PREFIX = "ROOM_";
    @GetMapping("/list")
    public PageResult list(AjRoomVo ajRoomVo){
        startPage();
        List<AjRoomVo> list = ajRoomService.selectRoomList(ajRoomVo);
        return getData(list);

    }
    @GetMapping("/{roomId}")
    public BaseResponse getRoomById(@PathVariable("roomId")Long roomId){
        AjRoomVo room = ajRoomService.getById(roomId);
        return BaseResponse.success(room);

    }
    @PostMapping
    public BaseResponse addRoom(@RequestBody AjRoomVo ajRoomVo){
        ajRoomVo.setRoomCode(CODE_PREFIX+System.currentTimeMillis());
        ajRoomVo.setRoomId(IdUtil.getSnowflake(1,1).nextId());
        boolean save = ajRoomService.save(ajRoomVo);
        return BaseResponse.success(save);
    }
    @PutMapping
    public BaseResponse updateRoom(@RequestBody AjRoomVo ajRoomVo){
        int b = ajRoomService.updateRoom(ajRoomVo);
        return BaseResponse.success(b);
    }


    @GetMapping("/queryPullDownAllRoom")
    public BaseResponse pullDownList(){

        List<RoomTree> roomTrees = ajRoomService.queryCommunityRoom();
//        List<RoomTree> roomTrees = ajRoomService.queryPullDownAllRoom();
        return BaseResponse.success(roomTrees);
    }




}
